

let addModuleDialog = {
  label: "新增",
  type: "button",
  actionType: "dialog",
  level: 'success',
  dialog: {
    title: "新增模块",
    size: "md",
    body: {
      type: "form",
      api: {
        method: "post",
        url: "/_dev/module/add",
        data: {
          "&": "$$",
          system_id: "${system_id}",
        },
      },
      body: [
        {
          type: 'select',
          name: "system_id",
          label: "系统名称",
          clearValueOnEmpty: true,
          required: true,
          source: {
            method: 'get',
            url: '/_dev/system/select',
          },
        },
        {
          type: "input-text",
          name: "m_code",
          maxLength: 15,
          label: "模块编号",
          clearValueOnEmpty: true,
          required: true,
        },
        {
          type: "input-text",
          name: "m_name",
          maxLength: 15,
          label: "模块名称",
          clearValueOnEmpty: true,
          required: true,
        },
        {
          type: "input-text",
          name: "m_desc",
          label: "描述",
          showCounter: true,
          maxLength: 128,
          clearValueOnEmpty: true,
          required: true,
        },
      ],
    },
    actions: [
      {
        label: "取消",
        type: "button",
        actionType: "close",
        level: "default",
      },
      {
        label: "确认",
        type: "button",
        actionType: "submit",
        level: "primary",
      },
    ],
  },
};

let editModuleDialog = {
  label: "编辑",
  type: "button",
  actionType: "dialog",
  level: "info",
  dialog: {
    title: "编辑模块",
    size: "md",
    body: {
      type: "form",
      api: {
        method: "post",
        url: "/_dev/module/edit",
        data: {
          "&": "$$",
          id: "${id}"
        },
      },
      body: [
        {
          type: 'select',
          name: "system_id",
          label: "系统名称",
          clearValueOnEmpty: true,
          required: true,
          disabled: true,
          source: {
            method: 'get',
            url: '/_dev/system/select',
          },
        },
        {
          type: "input-text",
          name: "m_code",
          maxLength: 15,
          label: "模块编号",
          clearValueOnEmpty: true,
          required: true,
        },
        {
          type: "input-text",
          name: "m_name",
          maxLength: 15,
          label: "模块名称",
          clearValueOnEmpty: true,
          required: true,
        },
        {
          type: "input-text",
          name: "m_desc",
          label: "描述",
          showCounter: true,
          maxLength: 128,
          clearValueOnEmpty: true,
          required: true,
        },
      ],
    },
    actions: [
      {
        label: "取消",
        type: "button",
        actionType: "close",
        level: "default",
      },
      {
        label: "确认",
        type: "button",
        actionType: "submit",
        level: "primary",
      },
    ],
  },
};

let delModuleButton = {
  label: "删除",
  type: "button",
  actionType: "ajax",
  level: "danger",
  confirmText: "确认模块[${m_code}]?",
  api: {
    method: "post",
    url: "/_dev/module/del",
    data: {
      id: "${id}",
    },
  },
};

let moduleFilter = {
  title: '',
  body: [
    {
      type: 'group',
      body: [
        {
          type: 'select',
          name: 'system_id',
          placeholder: '系统名称',
          size: 'sm',
          clearable: true,
          source: '/_dev/system/select',
        },
        {
          type: 'input-text',
          name: 'm_code',
          clearable: true,
          placeholder: '模块编号',
          size: 'sm',
        },
        {
          type: 'input-text',
          name: 'm_name',
          clearable: true,
          placeholder: '模块名称',
          size: 'sm',
        },
        {
          type: 'button-toolbar',
          buttons: [
            {
              type: 'reset',
              label: '重置',
            },
            {
              type: 'submit',
              level: 'primary',
              label: '查询',
            },
          ],
        },
      ],
    },
  ],
  actions: [],
}

let moduleTable = {
  type: "crud",
  autoFillHeight: true,
  syncLocation: false,
  perPage: 10,
  filter: moduleFilter,
  columnsTogglable:true,
  alwaysShowPagination: true,
  filterTogglable: true,
  headerToolbar: ['reload', 'bulkActions', 'filter-toggler', addModuleDialog],
  footerToolbar: [
    'statistics',
    {
      type: 'pagination',
      layout: 'perPage,pager,go',
    },
  ],
  
  tital: "",
  api: {
    method: "get",
    url: "/_dev/module/list",
    data: {
      system_id: "${system_id|default:undefined}",
      m_code: "${m_code|default:undefined}",
      m_name: "${m_name|default:undefined}",
      m_desc: "${m_desc|default:undefined}",
      page: "${page}",
      perPage: "${perPage|default:undefined}",
      orderBy: "${orderBy|default:undefined}",
    },
  },
  columns: [
    {
      name: "sys_name",
      label: "系统名称",
    },
    {
      name: "m_code",
      label: "模块编号",
      sortable: true,
    },
    {
      name: "m_name",
      label: "模块名称",
      sortable: true,
    },
    {
      name: 'resource_count',
      label: '资源数',
    },
    {
      name: 'interface_count',
      label: '接口数',
    },
    {
      name: "m_desc",
      label: "模块描述",
    },
    {
      type: "operation",
      label: "操作",
      buttons: [editModuleDialog, delModuleButton],
      width: 150,
    },
  ],
};


export { addModuleDialog,moduleTable }
